﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using QLNet;
using FinPlusCompCore;
using p = FinPlusCompQuant.QLConvParser;

namespace FinPlusCompQuant
{
    public class SwapRate : Rate
    {
        public RelinkableHandle<Quote> Spread { get; private set; }

        //construct
        public SwapRate(Market market, string name, double rate, double spread, string tenor, int fixingDays, int forwardStart, string floatLegIndex, string fixedLegFreq, string fixedLegDayCount, string fixedLegBizConv, string holidays, bool endOfMonth = true)
        {
            Id = name;

            Quote = market.GetQuote(name);
            Quote.linkTo(new SimpleQuote(rate));

            Spread = new RelinkableHandle<Quote>(new SimpleQuote(spread));

            var index = market.GetIndex(floatLegIndex);
            RateHelper = new SwapRateHelper(Quote, p.GetPeriod(tenor), p.Calendar(holidays), p.Freq(fixedLegFreq), p.BizConv(fixedLegBizConv), p.DayCount(fixedLegDayCount), index, Spread, forwardStart * p.GetPeriod("days"));
            market.SetRateHelper(name, RateHelper);
        }
    }
}
